﻿// JavaScript Document

/*
	Description
		Determines whether a string can be converted to a numeric value. 
	Returns
		True, if string can be converted to a number; False, otherwise.
*/
function isNumeric(string) {

	if (string == undefined) return false;

	var re = /^[-\+]?\d+(\.\d+)?$/;

	return re.test(string);	
}

/*
	Description
		Removes leading and trailing spaces and control characters from a string.
	Returns
		A copy of the string parameter, after removing leading and trailing spaces and control characters.
	Category
		String functions
	Function syntax
		Trim(string)	
*/
function trim (str) {
	
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	
	while (ws.test(str.charAt(--i)));
	
	return str.slice(0, i + 1);
}

/*
	Description
		Determines the length of a string or binary object.
	Returns
		Number; length of a string or a binary object.
	Category
		String functions
	Function syntax
		Len(string or binary object)
*/
function len (str) {
	return String(str).length;
}

/*
	Description
		Returns up to the leftmost count characters in a string.
	Returns
		String; up to the first count characters in the string parameter.
	Category
		String functions
	Function syntax
		Left(string, count)
*/
function left (str, n) {
	
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0, n);
		
}

/*
	Description
		Gets a specified number of characters from a string, beginning at the right.
		Returns the specified number of characters from the end (or right side) of the specified string.
	Returns
		•If the length of the string is greater than or equal to count, the rightmost count characters of the string
		•If count is greater than the length of the string, the whole string
		•If count is greater than 1, and the string is empty, an empty string
	Category
		String functions
	Function syntax
		Right(string, count)
*/
function  right (str, n) {

	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else {
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
	
}





